Search This Blog

Showing posts with label Delphi Land. Show all posts

gravatar

Delphi: Menampilkan gambar di sel DBGrid

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
bitmap : TBitmap;
fixRect : TRect;
bmpWidth : integer;
imgIndex : integer;

Begin
   fixRect := Rect;

   // customizing the 'LastName' field
   if Column.Field = EmployeeTableLastName then
   begin
     //adding some logic to grab the required image
     if EmployeeTableSalary.Value > 50000 then
       imgIndex := 0
     else if EmployeeTableSalary.Value > 25000 then
       imgIndex := 1
     else
       imgIndex := 2;


     bitmap := TBitmap.Create;
     try
     //grab the image from the ImageList 
     //(using the "Salary" field's value)
       ImageList1.GetBitmap(imgIndex,bitmap);
     //Fix the bitmap dimensions
       bmpWidth := (Rect.Bottom - Rect.Top);
       fixRect.Right := Rect.Left + bmpWidth;
     //draw the bitmap
       DBGrid1.Canvas.StretchDraw(fixRect,bitmap);
     finally
       bitmap.Free;
     end;

     // reset the output rectangle, 
     // add space for the graphics
     fixRect := Rect;
     fixRect.Left := fixRect.Left + bmpWidth;
   end;

   //draw default text (fixed position)
   DBGrid1.DefaultDrawColumnCell(fixRect, DataCol, Column, State);
end;

gravatar

Delphi : Scrolling DBGrid

Memfungsikan Mouse Scroll pada GRID
- Buat Procedure berikut :

procedure TForm1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
begin
  if (Msg.message = META_SETTEXTJUSTIFICATION) then
    if ActiveControl is TDBGrid then
    begin
      if msg.wParam >0 then
        SendMessage(ActiveControl.Handle,WM_KEYDOWN,VK_UP,0)
      else
        SendMessage(ActiveControl.Handle,WM_KEYDOWN,VK_DOWN,0);
   handled := true;
   end
end;


- Tambahkan pada Main Form event Form Create :
  Application.OnMessage := MyMessageHandler;

gravatar

Speed up the display of Delphi list components


If you use a Delphi component like a ListBox, Memo, TreeList, ListView,... and you add or modify a lot of items (lines, nodes,...), the component's performance becomes very slow. This is due to the fact that after each change, it is redrawn on the screen.

Thus, modifying 10000 items of a ListBox causes 10000 redraws, and that takes from several seconds to several minutes, depending on the computer's speed and the complexity of the process. Imagine how slow it can become if the process involves inserting, deleting, modifying and swapping many thousands of items.

But you can speed up things enormously with the following tip:

Call BeginUpdate before making the changes to the items. When all changes are complete, call EndUpdate to show the changes on screen. BeginUpdate and EndUpdate prevent excessive redraws and speed up processing time when items are added, deleted, or inserted.

Read more »

gravatar

Play Flash File in Delphi

To make use of SWF files in your Delphi application you should have the swf plugin installed then follow these steps:

In the Delphi IDE
- click on "Component", "Import ActiveX Control"
- chose "Shockwave Flash" and click on "install".

Now you have a TShockwaveFlash component in your IDE on the ActiveX tabsheet. Place the TShockwaveFlash Component onto your form, resize it as needed but for now do not assign a movie to it.

You will need to register the ocx file if it is not installed on the target computer. So you should have a resource file with
- the swflash.ocx and your Flash ( *.swf) file.
- Copy swflash.ocx (from i.e. windows\system32\macromed\flash) and your custom swf file to your project path.
- Create a textfile with a code like this:

SHOCKWAVEFILE RCDATA yourfile.swf
SHOCKWAVEOCX RCDATA swflash.ocx

(Where yourfile.swf is your swf-file)

- Save this file as flash.rc
- Goto Commandline, change to your project dir and enter the line:
"Brcc32 -r flash.rc"
- Now you have your new resource as flash.res file


uses ShockwaveFlashObjects_TLB; // will be used automatically
{...}

implementation

{$R *.DFM}
{$R flash.res} // your new created resource
{...}

procedure TForm1.FormCreate(Sender: TObject);
var
SystemDir : array[0..MAX_PATH] of Char;
SWFDir, AppDir: String;
Fres: TResourceStream;
Ffile: TFileStream;
begin
GetSystemDirectory(@SystemDir,MAX_PATH);
SWFDir := SystemDir+'\macromed\flash\';
GetDir(0,AppDir); // Get current directory

//check whether the sw-flash ocx is already installed
if fileexists(SWFDir+'swflash.ocx')=false then begin
//create directories if needed and extract file from resource.
{$i-} //compiler directive to suppress i/o error messages
MkDir(SystemDir+'\macromed');
MKDir(SystemDir+'\macromed\flash');
{$i+}
Fres := TResourceStream.Create(0,'SHOCKWAVEOCX',RT_RCDATA);
Ffile := TFileStream.Create(SWFDir+'swflash.ocx',fmCreate);
Ffile.CopyFrom(Fres,Fres.Size);
Fres.Free;
Ffile.Free;

//register ocx (simple but useful)
winexec(PChar('regsvr32 /s '+SWFDir+'swflash.ocx'),SW_HIDE);
end;
// extract ShockwaveFile from resource to application directory
Fres := TResourceStream.Create(0,'SHOCKWAVEFILE',RT_RCDATA);
Ffile := TFileStream.Create('flashmovie.swf',fmCreate);
Ffile.CopyFrom(Fres,Fres.Size);
Fres.Free;
Ffile.Free;

//Assign the extracted swf file to your TShockwaveFlash object
FlashMovie.Movie := AppDir+'\flashmovie.swf';
end;


If you dont want to have the popup menu displayed on right click you may use this step.

Place an "Application Events" component onto the form.
On the "OnMessage" Event place the following code:

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if Msg.message = WM_RBUTTONDOWN then Handled := True;
end;

If by chance you wanted to place your own popupmenu, then do the following:

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if Msg.message = WM_RBUTTONDOWN then
begin
popupmenu1.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
Handled := True;
end;
end;

Hope that helps someone that wanted to know how to do this

gravatar

Delphi VCL Komponen

Gue barusan search.. Cari2 komponen buat bikin program n akhirnya dapat nih link yang lumayan komplit..

http://www.mechodownload.com/forum/templates-scripts-gfx/87795-delphi-bcb-components.html

sebelumnya gw juga pernah dapet link yang ok juga tapi webnya dari cina pake tulisan cina pula... emang agak sulit utk nyari n donlodnya.. harus pake penerjemah dulu (http://babelfish.yahoo.com) biar bisa dibaca..

http://delphifans.com

smoga bermanfaat.

gravatar

Konfigurasi BDE di Windows Vista

Sekedar Share...
Bagi anda yang suka dengan pemrograman delphi dan sering bekerja dengan database paradox atau BDE di Windows Vista pasti akan menjumpai masalah seperti yang pernah gw alami. BDE selalu berhenti / hang ketika kita menghapus atau membuat object DB.
Permasalahannya adalah pada hak akses. solusinya ada 2 langkah :

*PertamaX*
1. memberikan hak akses ke semua user di registry windows.
- klik start run kemudian ketik regedit..
- HKEY_LOCAL_MACHINE
|-> SOFTWARE
|->BORLAND.
- klik kanan atau dari menu edit dan pilih Permission
- klik “Users”.
- pada "Permission for user", pilih “Full Control” dan klik ok

- kemudian Exit untuk keluar Registry Editor

*Kedua*
2. Ganti "Net Dir" melalui BDE configuration.
Untuk sharing data, BDE dikendalikan oleh file "PDOXUSRS.NET" dan default lokasinya adalah di "C:\" yang oleh windows vista tidak diperbolehkan (not permited). So kita harus membuat folder dan seting BDE untuk mengarah ke folder tsb:
- buat folder dengan nama terserah (misal "BDEShare")
- dari control panel buka/jalankan "Borland Database Engine"
- pilih pada tab "configuration"
- Configuration
|-> Drivers
|-> Native
|-> PARADOX
- pada bagian "Definition" ubah folder NET DIR ke folder yang barusan dibuat (C:\BDEShare)
- kilk menu "Object" dan pilih "Apply"
- Tutup dan selesai...

Sekarang anda bisa membuat database object pada BDE dengan nyaman..